package git.bds.nyc.demand.convert;

import git.bds.nyc.demand.model.domain.CorpDemand;
import git.bds.nyc.demand.model.domain.FarmerDemand;
import git.bds.nyc.demand.model.dto.DemandAddDTO;
import git.bds.nyc.demand.model.dto.DemandModifyDTO;
import git.bds.nyc.demand.model.ee.DemandEs;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * @author 成大事
 * @since 2022/11/2 10:44
 */
@Mapper
public interface DemandCovert {

    DemandCovert INSTANCE = Mappers.getMapper(DemandCovert.class);

    /**
     * 添加需求
     *
     * @param demandAddDTO 需求操作数据
     * @param userId           用户id
     * @return {@link CorpDemand}
     */
    @Mapping(source = "userId",target = "userId")
    CorpDemand toCorpDemandForAdd(DemandAddDTO demandAddDTO, Long userId);

    /**
     * 要求修改
     *
     * @param userId          用户id
     * @param demandModifyDTO 需求修改数据
     * @return {@link CorpDemand}
     */
    @Mapping(source = "userId",target = "userId")
    CorpDemand toCorpDemandForModify(DemandModifyDTO demandModifyDTO, Long userId);


    /**
     * 添加需求
     *
     * @param demandAddDTO 需求操作数据
     * @param userId           用户id
     * @return {@link CorpDemand}
     */
    @Mapping(source = "userId",target = "userId")
    FarmerDemand toFarmerDemandForAdd(DemandAddDTO demandAddDTO, Long userId);

    /**
     * 要求修改
     *
     * @param userId          用户id
     * @param demandModifyDTO 需求修改数据
     * @return {@link CorpDemand}
     */
    @Mapping(source = "userId",target = "userId")
    FarmerDemand toFarmerDemandForModify(DemandModifyDTO demandModifyDTO, Long userId);


    /**
     * 要求es
     *
     * @param corpDemand      公司需求
     * @param detailedAddress
     * @param type            类型
     * @return {@link DemandEs}
     */
    @Mapping(source = "type",target = "demandType")
    @Mapping(source = "detailedAddress",target = "detailedAddress")
    @Mapping(expression = "java(corpDemand.getDemandSpecies() + '-' +corpDemand.getDemandVariety())",target = "demandName")
    DemandEs toDemandEs(CorpDemand corpDemand,String detailedAddress,int type);

    /**
     * 要求es
     *
     * @param farmerDemand    农民需求
     * @param type            类型
     * @param detailedAddress 详细地址
     * @return {@link DemandEs}
     */
    @Mapping(source = "type",target = "demandType")
    @Mapping(source = "detailedAddress",target = "detailedAddress")
    @Mapping(expression = "java(farmerDemand.getDemandSpecies() + '-' +farmerDemand.getDemandVariety())",target = "demandName")
    DemandEs toDemandEs(FarmerDemand farmerDemand,String detailedAddress, int type);


}
